import Mock from 'mockjs';

// 定义返回的产品数据类型
interface Product {
  id: number;
  name: string;
  price: number;
  description: string;
  image: string;
  createdAt: string;
}

// 模拟产品列表数据
export const mockProductList = Mock.mock({
  'list|5-15': [
    {
      'id|+1': 1000,
      'name': '@ctitle(5, 10)',
      'price|1-1000.2': 1,
      'description': '@cparagraph(1, 3)',
      'image': '@image(300x200)',
      'createdAt': '@datetime',
    } as unknown as Product, // 修改点：先断言为 unknown 再断言为 Product
  ],
});

export default [
  // 获取产品列表
  {
    url: '/api/products',
    method: 'get',
    response: () => {
      return {
        code: 200,
        message: 'success',
        data: mockProductList.list,
      };
    },
  },
];